package com.ruoyi.common.utils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class ConvertUtil {

    public static Map<String, Object> objectToMap(Object obj) {
        if (obj == null) {
            return null;
        }

        Map<String, Object> map = new HashMap<>();
        Class<?> clazz = obj.getClass();

        for (Field field : clazz.getDeclaredFields()) {
            field.setAccessible(true); // 确保可以访问私有字段
            try {
                map.put(field.getName(), field.get(obj));
            } catch (IllegalAccessException e) {
                // 处理异常
                e.printStackTrace();
            }
        }

        return map;
    }
}